package cn.raven.system.service.impl;

import cn.raven.basic.service.impl.BaseServiceImpl;
import cn.raven.system.domain.SystemDicDetail;
import cn.raven.system.domain.SystemDicType;
import cn.raven.system.mapper.SystemDicDetailMapper;
import cn.raven.system.mapper.SystemDicTypeMapper;
import cn.raven.system.service.ISystemDicTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**

* @Description: 数据字典类型实现类
* @Author: king
* @Version: 1.0
* @Date:  2022/6/29 9:49
  */
@Service
//只读事务
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class SystemDicTypeServiceImpl extends BaseServiceImpl<SystemDicType> implements ISystemDicTypeService {
    @Autowired
    private SystemDicTypeMapper systemDicTypeMapper;
    @Autowired
    private SystemDicDetailMapper systemDicDetailMapper;

    /** 
    * @Title: del
    * @Description: 删除主表数据时根据数据id删除从表数据
    * @Author: king
    * @Version: 1.0
    * @Date:  2022/6/29 22:05  
    * @Parameters: [id]
    * @Return void
      */
    @Override
    public void del(Long id) {
        List<SystemDicDetail> types = systemDicDetailMapper.findAll();
        for (SystemDicDetail type : types){
            if (type.getTypes_id() == id){
                systemDicDetailMapper.delTypeId(id);
            }
        }
        systemDicTypeMapper.del(id);
    }
}
